package com.chang.order.web;

import com.chang.order.entity.OrderEntity;
import jakarta.annotation.Resource;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Date;
import java.util.UUID;

/**
 * @author: changzhenxi
 * @date: 2025年01月03日 11:02
 * @Version: 1.0
 * @description:
 */
@Controller
public class HelloController {

    @Resource
    RabbitTemplate rabbitTemplate;

    @ResponseBody
    @GetMapping("test/createOrder")
    public String createOrder(Model model) {
        OrderEntity orderEntity = new OrderEntity();
        orderEntity.setOrderSn(UUID.randomUUID().toString());
        orderEntity.setModifyTime(new Date());
        // 发消息至mq
        rabbitTemplate.convertAndSend("order-event-exchange", "order.create", orderEntity);
        return "ok";

    }

    @GetMapping("{page}.html")
    public String listPage(@PathVariable String page, Model model) {
        return page;
    }

}
